//
//  Macro.h
//  EPTool
//
//  Created by guoshiqing on 2018/4/3.
//  Copyright © 2018年 云数动能. All rights reserved.
//

#ifndef Macro_h
#define Macro_h

#import "EPColor.h"
#import "BaseJSONEntity.h"


//delegate宏
#define TheApp           ([UIApplication sharedApplication])
#define TheAppDel        ((AppDelegate *)([UIApplication sharedApplication].delegate))

#define ResignFirstResponder [[[UIApplication sharedApplication] keyWindow] endEditing:YES];


// 字体
#define BoldSystemFont(size)     [UIFont boldSystemFontOfSize:size]
#define SystemFont(size)         [UIFont systemFontOfSize:size]

// 画一像素线的宏
#define UI_1_PX_SIZE             (1 / [UIScreen mainScreen].scale)



// 头部字体
//#define FONT_NAVIGATION_BAR      SystemFont(17)
// 通用字体
#define FONT_NORMAL1              SystemFont(16)
// 通用字体
#define FONT_NORMAL2              SystemFont(14)
// 通用字体
#define FONT_NORMAL3              SystemFont(12)
// 通用字体
#define FONT_NORMAL4              SystemFont(21)
// 通用字体
#define FONT_NORMAL5              SystemFont(13)
#define FONT_NORMAL6              SystemFont(15)

/** 字符串比较 */
//比较版本号a,b： 1.0.2 < 1.1.0
#define VERSION_EQUAL_TO(a,b)                   ([(a) compare:(b) options:NSNumericSearch] == NSOrderedSame)
#define VERSION_GREATER_THAN(a,b)               ([(a) compare:(b) options:NSNumericSearch] == NSOrderedDescending)
#define VERSION_GREATER_THAN_OR_EQUAL_TO(a,b)   ([(a) compare:(b) options:NSNumericSearch] != NSOrderedAscending)
#define VERSION_LESS_THAN(a,b)                  ([(a) compare:(b) options:NSNumericSearch] == NSOrderedAscending)
#define VERSION_LESS_THAN_OR_EQUAL_TO(a,b)      ([(a) compare:(b) options:NSNumericSearch] != NSOrderedDescending)

/////////////////////////////////////////////////////////////////////////////////////////////////////////

// 判断系统版本号
#ifndef SYSTEM_VERSION
#define SYSTEM_VERSION                          ([[[UIDevice currentDevice] systemVersion] doubleValue])
#endif
#define IOS8            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0)
#define IOS9            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 9.0)
#define IOS10            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 10.0)
#define IOS11            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 11.0)
#define IOS12            ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 12.0)

#define IS_IPHONE4                  (UI_SCREEN_HEIGHT == 480)
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height == 568) ? YES : NO)
#define IS_IPhone6 (667 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)
#define IS_IPhone6plus (736 == [[UIScreen mainScreen] bounds].size.height ? YES : NO)
#define IS_IPhoneX (((int)((UI_SCREEN_HEIGHT/UI_SCREEN_WIDTH)*100) == 216)?YES:NO)

#define IPhoneX_FixHeight (IS_IPhoneX ? 34 : 0) //UITabBar高度 iPhone X 偏差34
#define TabBar_Height (IS_IPhoneX ? 83 : 49)//UITabBar高度 iPhone X = 83，其他49
#define NavBar_Height (IS_IPhoneX ? 88 : 64)//导航栏高度 iPhone X = 88，其他64
#define NavStatusBar_Height (IS_IPhoneX ? 44 : 20) //状态栏高度 iPhone X = 44，其他20
#define EPContentViewHeight (UI_SCREEN_HEIGHT - NavBar_Height - IPhoneX_FixHeight) // 内容高度
#define EPContentViewFrame CGRectMake(0, 0, UI_SCREEN_WIDTH, EPContentViewHeight) // 内容尺寸
///////////////////////////////////////////////////////////////////////////////
// app版本号
#define BundleVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
///////////////////////////////////////////////////////////////////////////////

// 屏幕宽度、高度、几倍屏
#define UI_SCREEN_WIDTH             ([[UIScreen mainScreen] bounds].size.width)
#define UI_SCREEN_HEIGHT            ([[UIScreen mainScreen] bounds].size.height)
#define UI_SCREEN_SCALE             (UI_SCREEN_WIDTH / 320)
#define UI_CONTENT_HEIGHT           (UI_SCREEN_HEIGHT - NavBar_Height)
#define UI_CONTENT_MAXY             (UI_SCREEN_HEIGHT - IPhoneX_FixHeight)
/** window*/
#define kWindow [UIApplication sharedApplication].keyWindow

///////////////////////////////////////////////////////////////////////////////


// 颜色定义
#define RGBA(r,g,b,a)               [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define RGB(r,g,b)                  [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]

#define RGB_HEX(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

// 随机色
#define RandomColor RGBA(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), 1.f)


#define WEAKSELF __weak typeof(self) weakSelf = self;


////////////////////////////////////// 语法糖 🍬 ///////////////////////
//定义返回请求数据的block类型
typedef void (^GetReturnBlock)(id returnValue, NSString *url);
typedef void (^GetErrorBlock)(id errorValue, NSString *url);
typedef void (^GetFailBlock)(id failValue, NSString *url);
typedef void (^ReturnValueBlock)(BaseJSONEntity *returnValue);
typedef void (^ErrorCodeBlock)(BaseJSONEntity *errorReturn);
typedef void (^FailureBlock)(BaseJSONEntity *failureReturn);
typedef void (^NetWorkBlock)(BOOL netConnetState);

typedef void (^NoParamsReturnBlock)(void);
typedef void (^StringBlock)(NSString *message);
typedef void (^String2Block)(NSString *message1, NSString *message2);
typedef void (^ProgressBlock)(float progress);
typedef void (^LogicalResultBlock)(BOOL yesNo);
typedef void (^IntegerResultBlock)(NSInteger iRet);


static inline void MainQueue(dispatch_block_t block){
    if ([NSThread isMainThread]) {
        block();
    } else {
        dispatch_async(dispatch_get_main_queue(), block);
    }
}

static inline void BackgroudQueue(dispatch_block_t block){
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        @autoreleasepool {
            if(block)
            {
                block();
            }
        }
    });
}


// 统一尺寸
#define LoginVC_X 32.f
#define LoginVC_W (UI_SCREEN_WIDTH - 2*LoginVC_X)

#define Cell_X 16.f
#define Cell_W (UI_SCREEN_WIDTH - 2*Cell_X)
#define Cell_H 44.f
#define Cell_Spacing_H 10.f
#define GlobalRowSpace 10.f
#define TempletBtn_H   64.f
#define CornerRadius   4.f

// 认证部分证件的比例是 54 : 85.6 = 0.63
#define CerPhoto_H (LoginVC_W * 0.63)
#define CerPhotoCell_H (CerPhoto_H + 160.f)


// 密码的最大长度
#define MAX_PASSWORD_LENGTH  32
// 密码的最小长度
#define MIN_PASSWORD_LENGTH  6

/*
 * 字体大小
 */
#define Font_S      10.f
#define Font_M      12.f
#define Font_L      14.f
#define Font_XL     16.f
#define Font_XXL    18.f
#define Font_XXXL   20.f


// 账号系统定义过程
typedef NS_ENUM(NSUInteger, AccountSystemDefineType){
    ForRegisterType = 0,     // 注册类型
    ForForgotType = 1,       // 找回密码类型
    ForModifyMobileType = 2, // 修改手机号码
    ForBindingMobileTypeFromWX = 3, // 微信绑定手机号码
    ForBindingMobileTypeFromFB = 4, // FaceBook绑定手机号码
};

typedef NS_ENUM(NSUInteger, PasswordShowType){
    PasswordShowType_Ciphertext = 0, // 密文
    PasswordShowType_Plaintext = 1,  // 明文
};


/**
 *  网络连接状态
 */
typedef NS_ENUM(NSUInteger, NetWorkState){
    NetWorkWifi = 0,      //wifi
    NetWorkWWAN,          //蜂窝网 2G,3G,4G...
    NetWorkUnknown,       //未识别的网络
    NetWorkDisconnect     //无网络连接
};

typedef NS_ENUM(NSUInteger, FreshDirectionType){
    FD_FirstLoad = 0,       // 第一次加载
    FD_DropDownRefresh = 1, // 下拉加载最新
    FD_PullupMore = 2,      // 上拉加载更多
};


typedef enum EPModuleType {
    EPModuleNone     = 0,  // 填白用
    EPModule1 = 1,
    
} EPModuleType;

#endif /* Macro_h */
